var LC_StatusIcon = {
    onStatusContextShowing : function(e) {
        document.getElementById('lc-chkEnabled').setAttribute("checked", LockCrypt.enabled);
        document.getElementById('lc-chkEnableSave').setAttribute("checked", LockCrypt.enableSave);
        document.getElementById('lc-chkEnableSave').setAttribute("disabled", !LockCrypt.enabled);
        document.getElementById('lc-chkAutoFill').setAttribute("checked", LockCrypt.autoFill);
        e.stopPropagation();
    },
    populateFormsStatus : function(e) {
        var popup = document.getElementById("lc-statusforms-pop");
        LC_StatusIcon.populateForms(popup);
        e.stopPropagation();
    },
    populateFormsToolbar : function(e) {
        var popup = document.getElementById("lc-toolbarforms-pop");
        LC_StatusIcon.populateForms(popup);
        e.stopPropagation();
    },
    populateForms : function(popup) {
        var forms = content.document.forms;
        while(popup.hasChildNodes()) {
            popup.removeChild(popup.firstChild);
        }
        if(forms.length > 0) {
            for(var i=0;i<forms.length;i++) {
                var thisForm = forms[i];
                var formName = LockCrypt.getFormId(thisForm);
                var itm = LC_StatusIcon.createMenuItem(formName === null ? LockCrypt.getString("untitled") : formName, i);
                itm.addEventListener("command", function(e) { 
                    LockCrypt.promptSaveByRef(content.document.forms[e.originalTarget.getAttribute('accesskey')], false, false); 
                    e.stopPropagation(); 
                }, false);
                popup.appendChild(itm);
            }
        } else {
            var itmDisabled = LC_StatusIcon.createMenuItem(LockCrypt.getString("noformsfound"), null);
            itmDisabled.setAttribute("disabled", "disabled");
            popup.appendChild(itm);
        }
    },
    createMenuItem : function(label, accesskey) {
        const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
        var item = document.createElementNS(XUL_NS, "menuitem");
        item.setAttribute("label", label);
        if(accesskey !== null) {
            item.setAttribute("accesskey", accesskey);
        }
        return item;
    }
};